package com.xysq.activity;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.zxing.WriterException;
import com.umeng.analytics.MobclickAgent;
import com.xysq.lemon.R;
import com.xysq.util.QRCodeUtil;
import com.xysq.util.UseUtil;

import butterknife.InjectView;

public class SettingsActivity extends BaseActivity {

    @InjectView(R.id.img_qr_code)
    ImageView qrCodeImg;
    @InjectView(R.id.txt_version)
    TextView versionTxt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);

        try {
            Bitmap bitmap = QRCodeUtil.getQrCodeImage(UseUtil.dp2Px(this, 150), UseUtil.dp2Px(this, 150), "http://www.xyooyo.com/download/ios/download.html", BitmapFactory.decodeResource(getResources(), R.drawable.def_img_head));
            qrCodeImg.setImageBitmap(bitmap);
        } catch (WriterException e) {
            e.printStackTrace();
        }

        try {
            versionTxt.setText("当前版本号：" + getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }

    public void toBack(View view) {
        onBackPressed();
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("设置页");
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("设置页");
        MobclickAgent.onPause(this);
    }
    @Override
    public void finish() {
        Intent intent = new Intent(this,MainTabActivity.class);
        intent.putExtra(MainTabActivity.INDEX, MainTabActivity.TAG_USER);
        startActivity(intent);
    }
}
